package com.demo.security.config.bean;

import java.io.IOException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;

import javax.annotation.PostConstruct;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.demo.security.utils.RSAUtils;

import lombok.Data;

@Data
@Configuration
@ConfigurationProperties("spring.security.rsa")
public class RsaProperties {

    private String publicKeyPath;
    private String privateKeyPath;

    private PublicKey publicKey;
    private PrivateKey privateKey;

    @PostConstruct
    public void initKey() throws InvalidKeySpecException, IOException {
        this.publicKey = RSAUtils.getPublicKey(publicKeyPath);
        this.privateKey = RSAUtils.getPrivateKey(privateKeyPath);
    }
}
